package hallows;

public class Registry {
	def DataStore dataset
	def WsdlIngester ingester
	
	def init() {
		dataset= new DataStore('lib/ws.owl')
		ingester= new WsdlIngester()
	}
	
	// take a String url and return a Map 
	// representing the structure of the web service
	def addWebService(String wsdlUrl) {
		Map service= ingester.readWsdl(wsdlUrl) 
		Map result= dataset.addWebService(service)
		println result['status']
	}
	
	// replace the current web service info with
	// the info contained in the new wsdl file
	def updateWebService(String wsdlUrl) {
		Map service= ingester.readWsdl(wsdlUrl)
		removeWebService(service['service'])
		Map result= dataset.addWebService(service)
		println result['status'] 
	}
	
	// delete the service with the provided String url
	// and also remove its operations and associated facts
	def removeWebService(String serviceUrl) {
		Map result= dataset.removeWebService(serviceUrl)
		println result['status']
	}

	// Adds subject, relation, and object to dataset
	def addMetadata(String subject, String relation, String object) {
		Map result= dataset.addFact(subject, relation, object)
		println result['status']
	}
	
	// Deletes all relevant metadata for that subject and relation,
	// then adds the provided content
	def editMetadata(String subject, String relation, String object) {
		Map deleteResult= removeMetadata(subject, relation)
		Map addResult= addMetadata(subject, relation, object)
		println addResult['status']
	}
	
	// Deletes all metadata related to the subject by the relation
	def removeMetadata(String subject, String relation) {
		Map result= dataset.removeFacts(subject, relation)
		println result['status']
	}
	
	def editPayload(String messageUrl, String rdfString) {
		
	}
	
	def removePayload(String messageUrl) {
		
	}

}
